package com.gec.hawaste.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gec.hawaste.entity.Examine;
import com.gec.hawaste.entity.ExamineDo;
import com.gec.hawaste.mapper.ExamineMapper;
import com.gec.hawaste.service.IExamineService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author gec
 * @since 2022-11-23
 */
@Service
public class ExamineServiceImpl extends ServiceImpl<ExamineMapper, Examine> implements IExamineService {

    // 考核成绩条件分页查询（多表查询examine、office、user三表）
    @Override
    public IPage<ExamineDo> selectByCondition(IPage<ExamineDo> page, Map<String, Object> params) {

        QueryWrapper<ExamineDo> query = new QueryWrapper<>();
        //拼接固定sql
        query.apply("ex.del_flag=0 AND ex.examine_user_id=su.id AND su.office_id=so.id")
                //拼接动态sql,mapper层获取该拼接语句作为条件
                .eq(params.containsKey("type") && !ObjectUtils.isEmpty(params.get("type")), "ex.type", params.get("type"))
                .like(params.containsKey("name") && !ObjectUtils.isEmpty(params.get("name")), "su.name", params.get("name"))
                .eq(params.containsKey("officeId") && !ObjectUtils.isEmpty(params.get("officeId")), "so.id", params.get("officeId"));

        // ExamineServiceImpl对应ExamineMapper则可以直接用baseMapper，但其他Mapper还是要先创一个变量
        return baseMapper.selectByCondition(page, query);
    }
}
